package com.symone.crawler.runnable;

import com.symone.crawler.App;
import com.symone.crawler.config.CrawlerConfig;
import com.symone.crawler.data.ProxyData;
import com.symone.crawler.service.ProxyService;

import java.util.Date;
import java.util.concurrent.ConcurrentMap;

public class ProxyThread implements Runnable {

    private static int RECORD_NUM = 10;

    @Override
    public void run() {
        Date startTime = new Date();
        while (true) {
            while (App.PROXY_DATA_QUEUE.isEmpty() && new Date().getTime() - startTime.getTime() > CrawlerConfig.PROXY_WAIT_TIME ) {
                startTime = new Date();
                new ProxyService(CrawlerConfig.PROXY_URL + RECORD_NUM).saveWithFetch();
                RECORD_NUM = 1;
            }
        }
    }
}
